﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;

namespace DGen
{
    /// <summary>
    /// Static Methods file designed to be generally useful.
    /// Last updated : 13th December 2008.
    /// </summary>
    /// 
    public class DGen
    {
        /// <summary>
        /// Reallocates an array with a new size, and copies the contents of the old array to the new array.
        /// </summary>
        /// <param name="oldArray">the old array, to be reallocated.</param>
        /// <param name="newSize">the new array size.</param>
        /// <returns>A new array with the same contents.</returns>
        public static Array ResizeArray(Array oldArray, int newSize)
        {
            int oldSize = oldArray.Length;
            Type elementType = oldArray.GetType().GetElementType();
            Array newArray = Array.CreateInstance(elementType, newSize);
            int preserveLength = Math.Min(oldSize, newSize);
            if (preserveLength > 0)
                Array.Copy(oldArray, newArray, preserveLength);
            return newArray;
        }






    }


}

/* 
 * StringTool section credits below. 
 * Author: aendenne
* Email: AutomateAnything@yahoo.com
* Create Date: April 21, 2007
* Last Modified Date: August 14, 2007
* Version: 2.1
* Very minor modifications by DLinehan in September 2008.
*/